﻿using System;

namespace Columbus
{
    public static class Execute
    {
        public static void AsyncPattern(
            Func<AsyncCallback, object, IAsyncResult> work,
            Action<IAsyncResult> complete,
            int timeout = 5000)
        {
            AsyncSynchroniser.MakeSynchronous(work, complete, timeout)();
        }

        public static TResult AsyncPattern<TResult>(
            Func<AsyncCallback, object, IAsyncResult> work,
            Func<IAsyncResult, TResult> complete,
            int timeout = 5000)
        {
            return AsyncSynchroniser.MakeSynchronous(work, complete, timeout)();
        }

        public static void AsyncPattern<TResult>(
            Func<TResult, AsyncCallback, object, IAsyncResult> work,
            TResult asyncArgument,
            Action<IAsyncResult> complete,
            int timeout = 5000)
        {
            AsyncSynchroniser.MakeSynchronous(work, asyncArgument, complete, timeout)();
        }

        public static TResult AsyncPattern<TArg, TResult>(
            Func<TArg, AsyncCallback, object, IAsyncResult> work,
            TArg asyncArgument,
            Func<IAsyncResult, TResult> complete,
            int timeout = 5000)
        {
            return AsyncSynchroniser.MakeSynchronous(work, asyncArgument, complete, timeout)();
        }

        public static void AsyncPattern<TArg, TArg2>(
            Func<TArg, TArg2, AsyncCallback, object, IAsyncResult> work,
            TArg asyncArgument,
            TArg2 asyncArgument2,
            Action<IAsyncResult> complete,
            int timeout = 5000)
        {
            AsyncSynchroniser.MakeSynchronous(work, asyncArgument, asyncArgument2, complete, timeout)();
        }

        public static TResult AsyncPattern<TArg, TArg2, TResult>(
            Func<TArg, TArg2, AsyncCallback, object, IAsyncResult> work,
            TArg asyncArgument,
            TArg2 asyncArgument2,
            Func<IAsyncResult, TResult> complete,
            int timeout = 5000)
        {
            return AsyncSynchroniser.MakeSynchronous(work, asyncArgument, asyncArgument2, complete, timeout)();
        }

        public static void AsyncPattern<TArg, TArg2, TArg3>(
            Func<TArg, TArg2, TArg3, AsyncCallback, object, IAsyncResult> work,
            TArg asyncArgument,
            TArg2 asyncArgument2,
            TArg3 asyncArgument3,
            Action<IAsyncResult> complete,
            int timeout = 5000)
        {
            AsyncSynchroniser.MakeSynchronous(work, asyncArgument, asyncArgument2, asyncArgument3, complete, timeout)();
        }

        public static TResult AsyncPattern<TArg, TArg2, TArg3, TResult>(
            Func<TArg, TArg2, TArg3, AsyncCallback, object, IAsyncResult> work,
            TArg asyncArgument,
            TArg2 asyncArgument2,
            TArg3 asyncArgument3,
            Func<IAsyncResult, TResult> complete,
            int timeout = 5000)
        {
            return AsyncSynchroniser.MakeSynchronous(work, asyncArgument, asyncArgument2, asyncArgument3, complete, timeout)();
        }
    }
}
